/* =========================================
 *       语音识别子服务 --- 服务器搭建 
 * =========================================*/

#include "speech_server.hpp"
#include "logger.hpp"
#include <gflags/gflags.h>

DEFINE_bool(run_mode, false, "程序的运行模式: false-调试 true-发布");
DEFINE_string(log_file, "", "指定日志的输出文件");
DEFINE_int32(log_level, 0, "指定日志输出等级");

DEFINE_string(registry_host, "http://127.0.0.1:2379", "服务注册中心地址");
DEFINE_string(base_service, "/service", "服务监控根目录");
DEFINE_string(instance_name, "/speech_service/instance", "当前服务的实例名称");
DEFINE_string(access_host, "127.0.0.1:8001", "当前实例的外部访问地址");

DEFINE_int32(listen_port, 8001, "Rpc服务器监听端口");
DEFINE_int32(rpc_timeout, -1, "Rpc连接空闲的超时上限(-1表无限空闲)");
DEFINE_int32(rpc_threads, 1, "Rpc的IO线程数");

DEFINE_string(app_id, "aaaaaaaaaaaa", "语音平台应用ID");
DEFINE_string(api_key, "bbbbbbbbbbbbbbbbbbbbbbbbbb", "语音平台API密钥");
DEFINE_string(secret_key, "ccccccccccccccccccccccccccccc", "语音平台加密密钥");

int main(int argc, char* argv[])
{
    google::ParseCommandLineFlags(&argc, &argv, true);
    shared::init_logger(FLAGS_run_mode, FLAGS_log_file, FLAGS_log_level);

    logging::LoggingSettings settings;
    settings.logging_dest = logging::LoggingDestination::LOG_TO_NONE;
    logging::InitLogging(settings);

    speech::SpeechServerBuilder speechServerBuilder;
    speechServerBuilder.makeAsrObject(FLAGS_app_id, FLAGS_api_key, FLAGS_secret_key);   // 构造语音识别对象
    speechServerBuilder.makeRpcServer(FLAGS_listen_port, FLAGS_rpc_timeout, FLAGS_rpc_threads);  // 构造rpc服务器
    speechServerBuilder.makeRegistrantObject(   // 构造服务注册对象, 进行服务注册
        FLAGS_registry_host, FLAGS_base_service + FLAGS_instance_name, FLAGS_access_host
    );
    speech::SpeechServerPtr speechServer = speechServerBuilder.build();
    speechServer->start();  
    return 0;
}